<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
	<base href="${pageContext.request.contextPath}/">
	<title>Title</title>
	<link rel="stylesheet" href="assets/layui/css/layui.css">
	<link rel="stylesheet" href="assets/css/base.css">
	<style>

	</style>
</head>
<body>
<div class="page">
	<form class="layui-form  fx-col" id="form" lay-filter="form_filter">

		<input type="hidden" name="clazz.id" value="${clazz.id}"/>
		<div class="layui-form-item">
			<label class="layui-form-label">所属年级</label>
			<div class="layui-input-block">
				<select name="clazz.gradeId" lay-verify="required" id="grade">
					<c:forEach items="${grades}" var="grade">
						<option value="${grade.id}">${grade.name}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">班级名称</label>
			<div class="layui-input-block">
				<input type="text" name="clazz.name" id="name" required  lay-verify="required" placeholder="请输入名称"
					   autocomplete="off" class="layui-input" value="${clazz.name}">
			</div>
		</div>
		<button  lay-submit="" class="layui-btn mt-15" id="save_btn" type="button">保存</button>
	</form>
</div>


</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="assets/layui/layui.all.js"></script>

<script>
	$(function () {
		var form = layui.form;


		form.val("form_filter", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
			"clazz.gradeId": "${clazz.gradeId}" // "name": "value"
		});


		//监听提交
		form.on('submit()', function(data){
			$.ajax({
				url: "clazz/save",
				type: "post",
				data: $("#form").serialize(),
				dataType: "json",
				success(res) {
					if (res.success) {
						layer.msg('保存成功', {icon: 6}, function () {
							window.parent.search();
						});

					} else {
						layer.msg(res.msg, {icon: 2});
					}
				}

			})
			return false;
		});



	})
</script>
</html>
